package in.srain.cube.views.ptr.demo.ui.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;

import java.sql.SQLOutput;

import in.srain.cube.mints.base.TitleBaseFragment;
import in.srain.cube.request.JsonData;
import in.srain.cube.util.LocalDisplay;
import in.srain.cube.views.banner.SliderBanner;
import in.srain.cube.views.ptr.demo.R;
import in.srain.cube.views.ptr.demo.base.DemoHomeActivity;
import in.srain.cube.views.ptr.demo.datamodel.SliderBannerDataModel;
import in.srain.cube.views.ptr.demo.event.DemoSimpleEventHandler;
import in.srain.cube.views.ptr.demo.event.EventCenter;
import in.srain.cube.views.ptr.demo.event.SliderBannerDataEvent;
import in.srain.cube.views.ptr.demo.ui.sliderbanner.SliderBannerController;

public final class SliderBannerFragment extends TitleBaseFragment {

    @Override
    protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        setHeaderTitle(R.string.cube_demo_slider_banner);
        String str="[{\"pic\":\"http:\\/\\/img5.duitang.com\\/uploads\\/blog\\/201406\\/30\\/20140630150534_EWUVY.thumb.jpeg\"},{\"pic\":\"http:\\/\\/img5.duitang.com\\/uploads\\/item\\/201406\\/25\\/20140625121626_ZmT5n.thumb.jpeg\"},{\"pic\":\"http:\\/\\/img4.duitang.com\\/uploads\\/blog\\/201307\\/31\\/20130731231806_4yGxV.thumb.jpeg\"},{\"pic\":\"http:\\/\\/img5.duitang.com\\/uploads\\/item\\/201406\\/28\\/20140628122218_fLQyP.thumb.jpeg\"},{\"pic\":\"http:\\/\\/img5.duitang.com\\/uploads\\/blog\\/201406\\/26\\/20140626131831_MrdKP.thumb.jpeg\"},{\"pic\":\"http:\\/\\/img5.duitang.com\\/uploads\\/blog\\/201406\\/16\\/20140616165201_nuKWj.thumb.jpeg\"},{\"pic\":\"http:\\/\\/img5.duitang.com\\/uploads\\/item\\/201406\\/25\\/20140625140308_KP4rn.thumb.jpeg\"},{\"pic\":\"http:\\/\\/img5.duitang.com\\/uploads\\/item\\/201406\\/25\\/20140625121604_2auuA.thumb.jpeg\"},{\"pic\":\"http:\\/\\/img4.duitang.com\\/uploads\\/item\\/201406\\/25\\/20140625131625_LmmLZ.thumb.jpeg\"},{\"pic\":\"http:\\/\\/img5.duitang.com\\/uploads\\/item\\/201406\\/25\\/20140625132851_mPmKY.thumb.jpeg\"},{\"pic\":\"http:\\/\\/img5.duitang.com\\/uploads\\/item\\/201406\\/25\\/20140625133312_ZtmW4.thumb.jpeg\"},{\"pic\":\"http:\\/\\/img5.duitang.com\\/uploads\\/item\\/201406\\/25\\/20140625164858_AuafS.thumb.jpeg\",\"title\":\"title: 12\"}]\n";

        View view = inflater.inflate(R.layout.fragment_slider_banner, null);

        final SliderBanner sliderBanner = (SliderBanner) view.findViewById(R.id.demo_slider_banner);
        LinearLayout.LayoutParams lyp = new LinearLayout.LayoutParams(LocalDisplay.SCREEN_WIDTH_PIXELS, SliderBannerController.Height);
        sliderBanner.setLayoutParams(lyp);
        final SliderBannerController sliderBannerController = new SliderBannerController(sliderBanner);
        sliderBannerController.play(JsonData.create(str));

//        EventCenter.bindContainerAndHandler(this, new DemoSimpleEventHandler() {
//
//            public void onEvent(SliderBannerDataEvent event) {
//                sliderBannerController.play(event.data.optJson("data"));
//                System.out.println("-------->"+event.data.optJson("data"));
//            }
//
//
//
//        }).tryToRegisterIfNot();

//        SliderBannerDataModel.getSliderBanner();


        view.findViewById(R.id.demo_slider_banner_next_page).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getContext(), "Coming soon.", 1).show();
            }
        });
        return view;
    }
    @Override
    public void onDestroy() {
        super.onDestroy();

        DemoHomeActivity.instance.getHeadBar().setVisibility(View.VISIBLE);
    }
}